package com.huawei.appgallery.forum.forum.impl;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import com.huawei.appgallery.forum.base.https.jgw.JGWTabDetailResponse;
import com.huawei.appgallery.forum.cards.bean.ForumFeedRecommendCardBean;
import com.huawei.appgallery.forum.cards.widget.ForumFeedLoginView;
import com.huawei.appgallery.forum.cards.widget.ForumFeedLoginView.b;
import com.huawei.appgallery.forum.forum.api.IFollowTabFragmentProtocol;
import com.huawei.appgallery.forum.forum.fragment.ForumFollowBaseFragment;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.LayoutData;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.NetworkRemindBar;
import com.huawei.appgallery.foundation.ui.framework.widget.NodataWarnLayout;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appmarket.service.infoflow.view.widget.PullDownListView;
import com.huawei.appmarket.service.infoflow.view.widget.TopTipsView;
import com.huawei.hmf.annotation.FragmentDefine;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Locale;
import o.bqx;
import o.bqy;
import o.brd;
import o.bri;
import o.brm;
import o.bsl;
import o.bsv;
import o.bun;
import o.bun.a;
import o.bun.d;
import o.bun.h;
import o.bve;
import o.ccp;
import o.chb;
import o.cia;
import o.cix;
import o.cvt;
import o.BaseRequest;
import o.CollectCheck;
import o.evr;

@FragmentDefine(alias = "ForumFollowTabFragment", protocol = IFollowTabFragmentProtocol.class)
public class ForumFollowTabFragment extends ForumFollowBaseFragment implements b, cix {
    private boolean ʻˊ = false;
    private ForumFeedLoginView ʻˋ;
    private TopTipsView ʼˋ;
    private c ﾞ;

    static class c extends Handler {
        private WeakReference<ForumFollowTabFragment> ˋ;

        c(ForumFollowTabFragment forumFollowTabFragment) {
            this.ˋ = new WeakReference(forumFollowTabFragment);
        }

        public void handleMessage(Message message) {
            ForumFollowTabFragment forumFollowTabFragment = (ForumFollowTabFragment) this.ˋ.get();
            if (forumFollowTabFragment == null) {
                return;
            }
            if (message.what == 1000) {
                forumFollowTabFragment.ॱˉ();
            } else if (message.what == 1001) {
                forumFollowTabFragment.ॱˌ();
            } else if (message.what == 1002) {
                forumFollowTabFragment.ʿˋ();
            }
        }
    }

    public void ˏ(Bundle bundle) {
        super.ˏ(bundle);
        this.ﾞ = new c(this);
    }

    public void X_() {
        IFollowTabFragmentProtocol iFollowTabFragmentProtocol = (IFollowTabFragmentProtocol) this.ﹳ.ॱ();
        this.ॱꜟ = iFollowTabFragmentProtocol.getSupportNetworkCache();
        this.ʼˊ = iFollowTabFragmentProtocol.getUri();
        this.ʼᐝ = iFollowTabFragmentProtocol.getFragmentID();
        ˎ(chb.SECONDARY_LIST_TAB);
        this.ʼ = new bsl(this, iFollowTabFragmentProtocol.getAppId(), this.ʼˊ, bsv.ॱ(iFollowTabFragmentProtocol.getDomainId()));
    }

    public void ˋʻ() {
        super.ˋʻ();
        if (!UserSession.getInstance().isLoginSuccessful()) {
            ॱˋ(true);
        }
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        super.ˋ(layoutInflater, viewGroup, bundle);
        if (this.ͺˎ instanceof PullDownListView) {
            this.ͺˎ.setFooterViewListener(this);
            ((PullDownListView) this.ͺˎ).setLoadingTips(this.ͺˎ.getContext().getResources().getString(h.ʼ));
        }
        this.ʼˋ = (TopTipsView) this.ॱˍ.findViewById(o.bun.c.ˋᐝ);
        if (!UserSession.getInstance().isLoginSuccessful()) {
            ˊॱ(0);
        }
        return this.ॱˍ;
    }

    public int ߵ() {
        return d.ʼ;
    }

    private void ॱˊ(String str) {
        if (this.ʼˋ != null) {
            this.ʼˋ.setTips(str);
            this.ʼˋ.setBackgroundColor(ॱˊ().getResources().getColor(a.ˏ));
            this.ʼˋ.ॱ(null);
        }
    }

    public void ˊ(int i, NetworkRemindBar networkRemindBar) {
        if (this.ʻˊ) {
            ॱˊ(ॱ(h.ᐝ));
        } else {
            super.ˊ(i, networkRemindBar);
        }
    }

    public cia ˊ(Context context) {
        return new bve(context);
    }

    public void ᐝ() {
        super.ᐝ();
        this.ʻˋ = null;
        ʽʽ();
        if (this.ͺˎ != null) {
            this.ͺˎ.setmPullRefreshing(false);
        }
        bqx.ˋ("ForumFollowTabFragment", "onDestroyView: " + this);
    }

    private void ˊॱ(int i) {
        if (i == 0) {
            if (this.ʻˋ == null && (this.ॱˍ instanceof FrameLayout)) {
                LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, -1);
                this.ʻˋ = new ForumFeedLoginView(this.ॱˍ.getContext());
                this.ʻˋ.setLoginListener(this);
                this.ॱˍ.addView(this.ʻˋ, layoutParams);
            }
            ˎ(this.ʻˋ, 0);
            ˎ(this.ʼˋ, 8);
            ˎ(this.ᐝʻ, 8);
        } else if (i == 8) {
            ˎ(this.ʻˋ, 8);
            ˎ(this.ʼˋ, 0);
        }
    }

    public void ˋ(cvt o_cvt) {
        if (!ʼʻ()) {
            o_cvt.setRequestType(BaseRequest.RequestStrategy.REQUEST_CACHE_FIRST);
        } else if ("".equals(this.ॱॱ)) {
            o_cvt.setRequestType(BaseRequest.RequestStrategy.REQUEST_NETWORK_REF_CACHE);
        }
        bqx.ˊ("ForumFollowTabFragment", "onSetRequestType: " + o_cvt.getRequestType());
    }

    public void ˈॱ() {
        this.ʻˊ = true;
        ᐝ(1);
        ʾᐝ();
        ʿˊ();
    }

    public boolean ˊ(TaskFragment taskFragment, TaskFragment.b bVar) {
        if (this.ͺˎ instanceof PullDownListView) {
            ((PullDownListView) this.ͺˎ).ʼॱ();
        }
        if (ˋ(bVar)) {
            JGWTabDetailResponse jGWTabDetailResponse = (JGWTabDetailResponse) bVar.ˋ;
            List<LayoutData> ᐝॱ = jGWTabDetailResponse.ᐝॱ();
            if (!CollectCheck.isEmpty((List) ᐝॱ)) {
                ForumFeedRecommendCardBean forumFeedRecommendCardBean = null;
                int i = 0;
                boolean z = false;
                for (LayoutData layoutData : ᐝॱ) {
                    if (!"forumfeedpostcard".equals(layoutData.ˏ()) || CollectCheck.isEmpty(layoutData.ˋ())) {
                        ForumFeedRecommendCardBean forumFeedRecommendCardBean2;
                        if (forumFeedRecommendCardBean == null && "forumfeedrecommendcard".equals(layoutData.ˏ()) && !CollectCheck.isEmpty(layoutData.ˋ())) {
                            Object obj = layoutData.ˋ().get(0);
                            if (obj instanceof ForumFeedRecommendCardBean) {
                                forumFeedRecommendCardBean2 = (ForumFeedRecommendCardBean) obj;
                                forumFeedRecommendCardBean = forumFeedRecommendCardBean2;
                            }
                        }
                        forumFeedRecommendCardBean2 = forumFeedRecommendCardBean;
                        forumFeedRecommendCardBean = forumFeedRecommendCardBean2;
                    } else {
                        i = layoutData.ˋ().size() + i;
                        z = true;
                    }
                }
                if (!z && forumFeedRecommendCardBean != null && ((brm) bVar.ˊ).ˎ() == 1 && jGWTabDetailResponse.ॱ() == 0) {
                    bqx.ˊ("ForumFollowTabFragment", "No feed post but find recommend , show empty layout");
                    forumFeedRecommendCardBean.ˎ(true);
                }
                ͺ(i);
            }
        }
        ॱˑ();
        boolean ˊ = super.ˊ(taskFragment, bVar);
        this.ʻˊ = false;
        return ˊ;
    }

    private void ॱˑ() {
        if (this.ʻˊ) {
            evr.ˊ().ᐝ();
        }
    }

    private boolean ˋ(TaskFragment.b bVar) {
        return bVar != null && (bVar.ˋ instanceof JGWTabDetailResponse) && bVar.ˋ.getResponseCode() == 0 && bVar.ˋ.getRtnCode_() == 0;
    }

    public void ˋ(bri o_bri, BaseDetailResponse baseDetailResponse) {
        if (baseDetailResponse.getResponseType() == ResponseBean.a.FROM_CACHE && this.ﾞ != null) {
            this.ﾞ.sendEmptyMessageDelayed(1002, 350);
        }
    }

    public void ˋॱ(boolean z) {
        if (UserSession.getInstance().isLoginSuccessful()) {
            super.ˋॱ(z);
        } else {
            ˎ(this.ߵ, 8);
            ˎ(this.ॱʿ, 8);
            ˎ(this.ͺˎ, 8);
            ˎ(this.ߴ, 8);
        }
        if (!(this.ߴ == null || this.ߴ.getVisibility() != 0 || this.ͺˎ == null)) {
            this.ͺˎ.setVisibility(0);
        }
        ˏॱ("setDataLayoutVisiable, isLoginSuccessful = " + UserSession.getInstance().isLoginSuccessful() + " ; ");
    }

    public void Y_() {
    }

    private void ॱˉ() {
        ॱˋ(true);
        ˊॱ(8);
        ˏॱ("onLogin, logout success : ");
    }

    private void ॱˌ() {
        if (this.י != null) {
            this.י.ॱॱ();
        }
        ᶥॱ();
        ॱˋ(true);
        ˊॱ(0);
        ˏॱ("onLogout, logout success : ");
    }

    public void onAccountBusinessResult(ccp o_ccp) {
        if (this.ﾞ == null) {
            return;
        }
        if (102 == o_ccp.ˎ) {
            ˏॱ("onAccountBusinessResult, login success : ");
            this.ﾞ.sendEmptyMessage(1000);
            this.ﾞ.post(new e(this));
        } else if (103 == o_ccp.ˎ) {
            ˏॱ("onAccountBusinessResult, logout success : ");
            this.ﾞ.sendEmptyMessage(1001);
        }
    }

    public void ˎͺ() {
        ˊॱ(false);
        this.ॱॱ = "";
        ᐝ(1);
        if (this.י != null) {
            int ˊॱ = this.י.ˊॱ();
            if ((ॱꜞ() || ꜝ() <= 1) && ˊॱ == 0) {
                ᶥॱ();
                ॱ(this.ᴵ);
            }
        }
        ॱˋ(true);
        ʿˊ();
    }

    private void ʿˋ() {
        if (this.ͺˎ instanceof PullDownListView) {
            ((PullDownListView) this.ͺˎ).ʽॱ();
        } else {
            bqx.ॱ("ForumFollowTabFragment", "pullDownRefresh, listView = " + this.ͺˎ);
        }
    }

    public int י() {
        return bun.b.ˏ;
    }

    public int ՙ() {
        return h.ˊ;
    }

    public void ͺˏ() {
        if (this.ߴ != null) {
            this.ߴ.setWarnImage(י());
            this.ߴ.setWarnTextOne(ՙ());
            this.ߴ.setViewVisible(NodataWarnLayout.e.WARN_BTN, 8);
            this.ߴ.setViewVisible(NodataWarnLayout.e.WARN_TEXTTWO, 8);
        }
    }

    public void ॱʾ() {
        if (this.ͺˎ != null) {
            this.ͺˎ.ˎ(8);
        }
    }

    public void ॱـ() {
        if (this.ͺˎ == null) {
            bqx.ˋ("ForumFollowTabFragment", "onHide error , listview null");
        } else if (!(this.י instanceof bve)) {
        } else {
            if (((bve) this.י).ˊ()) {
                this.ͺˎ.ˎ(0);
            } else {
                this.ͺˎ.ˎ(8);
            }
        }
    }

    private void ͺ(int i) {
        brd.ॱ.ˋ(bqy.ˋ().ˎ(ॱˋ()), bqy.ˋ().ˎ(), this.ʼˊ, i);
    }

    public void ʾॱ() {
        super.ʾॱ();
        this.ﾞ.sendEmptyMessage(1002);
    }

    public boolean ad_() {
        return false;
    }

    private void ˏॱ(String str) {
        StringBuilder stringBuilder = new StringBuilder("LogForMonekyError ==>> ");
        stringBuilder.append(str);
        if (this.ʻˋ == null) {
            stringBuilder.append("loginView is null ; ");
        } else {
            stringBuilder.append(String.format(Locale.ENGLISH, "loginViewVisibility = %d ; ", new Object[]{Integer.valueOf(this.ʻˋ.getVisibility())}));
        }
        if (this.ߴ == null) {
            stringBuilder.append("noDataView is null ; ");
        } else {
            stringBuilder.append(String.format(Locale.ENGLISH, "noDataViewVisibility = %d ; ", new Object[]{Integer.valueOf(this.ߴ.getVisibility())}));
        }
        if (this.ͺˎ == null) {
            stringBuilder.append("listView is null ; ");
        } else {
            stringBuilder.append(String.format(Locale.ENGLISH, "listView = %d ; ", new Object[]{Integer.valueOf(this.ͺˎ.getVisibility())}));
        }
        bqx.ˊ("ForumFollowTabFragment", stringBuilder.toString());
    }
}
